package br.com.gecandango.portlets.cardapio;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import br.com.gecandango.service.CardapioService;
import br.com.gecandango.service.PratoService;
import br.com.gecandango.service.RefeicaoService;

import com.liferay.portal.struts.PortletAction;

public abstract class CardapioAction extends PortletAction {

	static ApplicationContext context = new ClassPathXmlApplicationContext(
			"applicationContext.xml");

	static CardapioService getCardapioService() {
		return (CardapioService) context.getBean("CardapioService");
	}
	static RefeicaoService getRefeicaoService() {
		return (RefeicaoService) context.getBean("RefeicaoService");
	}
	static PratoService getPratoService() {
		return (PratoService) context.getBean("PratoService");
	}
	
	
	public abstract void processAction(ActionMapping mapping, ActionForm form,
			PortletConfig config, ActionRequest req, ActionResponse res)
			throws Exception;

	public ActionForward render(ActionMapping mapping, ActionForm form,
			PortletConfig config, RenderRequest req, RenderResponse res)
			throws Exception {
		if (getForward(req) != null && !getForward(req).equals("")) {
			return mapping.findForward(getForward(req));
		} else {
			return mapping.findForward("portlet.ext.contato.view");
		}
	}

}
